package com.boarsoft.boar.gateway.activemq.test;

import javax.jms.Session;
import javax.jms.TextMessage;

import com.boarsoft.common.util.JsonUtil;
import com.boarsoft.message.bean.Message;
import com.boarsoft.message.jms.JmsMsgConverter;

public class DemoJmsMsgConverter implements JmsMsgConverter {

	@Override
	public Message convert(javax.jms.Message am) throws Exception {
		String o = ((TextMessage) am).getText();
		Message m = JsonUtil.parseObject(o, Message.class);
		return m;
	}

	@Override
	public javax.jms.Message convert(Session session, Message m) throws Exception {
		// return session.createTextMessage((String) m.getContent());
		return session.createTextMessage(m.toJson());
	}
}
